package com.wj.tool.common.exception;


import com.wj.tool.common.exception.message.ApplicationMessage;

public abstract class BusinessException extends RuntimeException {

    protected final int code;
    protected final ApplicationMessage applicationMessage;
    protected String message;

    public BusinessException(ApplicationMessage applicationMessage) {
        this.message = applicationMessage.getMessage();
        this.code = applicationMessage.getCode();
        this.applicationMessage = applicationMessage;
    }

    public BusinessException(ApplicationMessage applicationMessage, Throwable cause) {
        super(cause);
        this.message = applicationMessage.getMessage();
        this.code = applicationMessage.getCode();
        this.applicationMessage = applicationMessage;
    }

    public BusinessException(ApplicationMessage applicationMessage, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(applicationMessage.getMessage(), cause, enableSuppression, writableStackTrace);
        this.message = applicationMessage.getMessage();
        this.code = applicationMessage.getCode();
        this.applicationMessage = applicationMessage;
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public ApplicationMessage getApplicationMessage() {
        return this.applicationMessage;
    }
}